package de.acagamics.roteschlupfmuetze.data;

import java.io.Serializable;
import java.util.LinkedList;

import de.acagamics.roteschlupfmuetze.core.LevelObject;

public class LevelData implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	public static int ITEM_SIZE = 80;
	public static int TILE_SIZE_X = 80; // TODO: adjust
	public static int TILE_SIZE_Y = 40; // TODO: adjust
	
	private int pitOffsetX = 400;
	private int pitOffsetY = 650;
	
	private int pitSizeX = 6;
	private int pitSizeY = 4;
	
	private int levelNumber = 0;
	private LinkedList<LevelObject> objects = null;
	
	private boolean drop = true;
	
	public LevelData() {
	}
	
	public int getPitOffsetX() {
		return pitOffsetX;
	}
	public int getPitOffsetY() {
		return pitOffsetY;
	}
	
	public void setPitOffsetX(int pitOffsetX) {
		this.pitOffsetX = pitOffsetX;
	}

	public void setPitOffsetY(int pitOffsetY) {
		this.pitOffsetY = pitOffsetY;
	}

	public void setPitSizeX(int pitSizeX) {
		this.pitSizeX = pitSizeX;
	}

	public void setPitSizeY(int pitSizeY) {
		this.pitSizeY = pitSizeY;
	}

	public int getPitSizeX() {
		return pitSizeX;
	}
	public int getPitSizeY() {
		return pitSizeY;
	}

	public int getLevelNumber() {
		return levelNumber;
	}
	
	public boolean getDrop() {
		return drop;
	}

	public void setLevelNumber(int levelNumber) {
		this.levelNumber = levelNumber;
	}

	public LinkedList<LevelObject> getObjects() {
		return objects;
	}

	public void setObjects(LinkedList<LevelObject> objects) {
		this.objects = objects;
	}
	
	public int getInventoryYPosition(int index) {
		return ITEM_SIZE * index + 20;
	}
	
	public void wasLoaded() {
		for(LevelObject object : objects) {
			object.wasLoaded();
		}
	}

	public int fromLevelX(int x) {
		double percent = (double)(pitSizeX*LevelData.TILE_SIZE_X - 10) / 100;
		return pitOffsetX + 5 + (int)(x * percent);
	}
	
	public int fromLevelY(int y) {
		double percent = (double)(pitSizeY*LevelData.TILE_SIZE_Y - 10) / 100;
		return pitOffsetY - 5 - (int)(y * percent);
	}

	public boolean isDrop() {
		return drop;
	}

	public void setDrop(boolean drop) {
		this.drop = drop;
	}
}
